package cn.hy.today;

import java.util.List;

class Solution_2865 {
    public long maximumSumOfHeights(List<Integer> maxHeights) {
        long ans = 0;
        int n = maxHeights.size();
        for (int i = 0; i < n; i++) {
            long pre = maxHeights.get(i);
            long sum = pre;
            for (int j = i - 1; j >= 0; j--) {
                pre = Math.min(pre, maxHeights.get(j));
                sum += pre;
            }
            long suf = maxHeights.get(i);
            for (int j = i + 1; j < n; j++) {
                suf = Math.min(maxHeights.get(j), suf);
                sum += suf;
            }
            ans = Math.max(ans, sum);
        }
        return ans;
    }
}